﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core.Packets
{
    public abstract class Packet
    {
        protected byte numeroConnexion;
        protected byte typePacket;

        public byte NumeroConnexion { get { return numeroConnexion; } }
        public byte TypePacket { get { return typePacket; } }

        public PacketTypes Primitive
        {
            get
            {
                return (PacketTypes)Enum.Parse(typeof(PacketTypes), typePacket.ToString());
            }
        }

        //public static Packet CreatePacketFromCharOfBitArray(string arrayOfBits)
        //{
        //    Packet packet;
        //    byte numeroConnexion;
        //    byte typeConnexion;
        //    for (int ctr = 0; ctr < 16; ctr += 8)
        //    {
        //        numeroConnexion = Convert.ToByte(arrayOfBits.Substring(ctr, 8), 2);
        //    }
        //    switch(
        //    return packet;
        //}

        public virtual string GetStringOfBitArray()
        {
            string arrayOfBits;
            arrayOfBits = Convert.ToString(numeroConnexion, 2).PadLeft(8, '0');
            arrayOfBits += Convert.ToString(typePacket, 2).PadLeft(8, '0');
            return arrayOfBits;
        }

        public static PacketTypes GetPacketType(byte type)
        { 
            return (PacketTypes)Enum.Parse(typeof(PacketTypes), type.ToString());
        }
    }
}
